//
//  TSTeamNormalTableViewCell.swift
//  TSProfitProject
//
//  Created by TmmmS on 2019/11/24.
//  Copyright © 2019 TMS. All rights reserved.
//

import UIKit
import HandyJSON

struct TSMyteamModel : HandyJSON {
    var id = 0
    var dengji = 0
    var liushui = 0
    var username : String? = nil
}

struct TSTeamAgentLevelModel : HandyJSON {
    var id = 0
    var gender = 0
    var money = 0
    var pro : Double = 0
}

class TSTeamNormalTableViewCell: UITableViewCell {

    var namelLabel : UILabel!
    var levelLabel : UILabel!
    var tradeLabel : UILabel!
    var peopleLabel : UILabel!
    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .none
        configViews()
        configLine()
    }
    
    func setupCell(name:String, userId:String, level:Int, trade:String, people:Int64) {
        
        namelLabel.text = String.init(format: "%@\n%@", name, userId)
        levelLabel.text = "\(level)"
        tradeLabel.text = trade
        peopleLabel.text = "\(people)"
    }
    
    func configViews() {
        
        namelLabel = createLabel(line: 0)
//        namelLabel.adjustsFontSizeToFitWidth = true
//        namelLabel.minimumScaleFactor = 0.6
        contentView.addSubview(namelLabel)
        namelLabel.snp.makeConstraints { (make) in
            make.left.equalTo(5)
            make.top.equalTo(10)
            make.width.equalTo(SCREEN_WIDTH*0.3 - 2*5)
            
            make.bottom.equalTo(-10)
        }
        
        levelLabel = createLabel(line: 1)
        contentView.addSubview(levelLabel)
        levelLabel.snp.makeConstraints { (make) in
            make.left.equalTo(namelLabel.snp_right).offset(10)
            make.centerY.equalTo(namelLabel)
            make.width.equalTo(SCREEN_WIDTH*0.2 - 2*5)
        }
        
        tradeLabel = createLabel(line: 1)
        contentView.addSubview(tradeLabel)
        tradeLabel.snp.makeConstraints { (make) in
            make.left.equalTo(levelLabel.snp_right).offset(10)
            make.centerY.equalTo(namelLabel)
            make.width.equalTo(SCREEN_WIDTH*0.3 - 2*5)
        }
        
        peopleLabel = createLabel(line: 1)
        contentView.addSubview(peopleLabel)
        peopleLabel.snp.makeConstraints { (make) in
            make.left.equalTo(tradeLabel.snp_right).offset(10)
            make.centerY.equalTo(namelLabel)
            make.width.equalTo(SCREEN_WIDTH*0.2 - 2*5)
        }
    }
    
    func configLine() {
        
        let line1 = drawLine()
        contentView.addSubview(line1)
        line1.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
        
        let line2 = drawLine()
        contentView.addSubview(line2)
        line2.snp.makeConstraints { (make) in
            make.left.equalTo(SCREEN_WIDTH*0.3)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
        
        let line3 = drawLine()
        contentView.addSubview(line3)
        line3.snp.makeConstraints { (make) in
            make.left.equalTo(SCREEN_WIDTH*0.5)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
        
        let line4 = drawLine()
        contentView.addSubview(line4)
        line4.snp.makeConstraints { (make) in
            make.left.equalTo(SCREEN_WIDTH*0.8)
            make.top.bottom.equalToSuperview()
            make.width.equalTo(1)
        }
    }
    
    func createLabel(line:Int) -> UILabel {
        
        let  label = UILabel.init()
        label.font = UIFont.systemFont(ofSize: 14, weight: .medium)
        label.textColor = UIColor.hexadecimalColor(hexadecimal: "#282828")
        label.textAlignment = .center
        label.numberOfLines = line
        return label
    }
    
    func drawLine() -> UIView {
        let line = UIView.init()
        line.backgroundColor = UIColor.hexadecimalColor(hexadecimal: "#DDDDDD")
        return line
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
